<template>
        <div id="thjl" class="container-fluid padding">
            <form class="layui-form layui-form-pane">
                <el-form :model="saveDatas" ref="saveDatas" label-width="180px" class="padding">
                    <fieldset class="layui-elem-field">
                        <legend>FreeSWITCH配置</legend>
                        <div class="layui-field-box" id="config">
                            <el-form-item label="http协议" prop="http">
                                <el-input v-model="saveDatas.http" ></el-input>
                            </el-form-item>
                            <el-form-item label="CRM服务器域名" prop="crmDomain">
                                <el-input v-model="saveDatas.crmDomain"></el-input>
                            </el-form-item>
                            <el-form-item label="FreeSWITCH服务器域名" prop="domain">
                                <el-input v-model="saveDatas.domain"></el-input>
                            </el-form-item>
                        </div>
                    </fieldset>
                    <fieldset class="layui-elem-field">
                        <legend>FreeSWITCH服务器Ftp配置</legend>
                        <div class="layui-field-box" id="config2">
                            <el-form-item label="FTP根路径" prop="root">
                                <el-input v-model="saveDatas.root" ></el-input>
                            </el-form-item>
                            <el-form-item label="FTP端口" prop="domain">
                                <el-input v-model="saveDatas.port"></el-input>
                            </el-form-item>
                            <el-form-item label="FTP用户名" prop="domain">
                                <el-input v-model="saveDatas.account"></el-input>
                            </el-form-item>
                            <el-form-item label="FTP密码" prop="domain">
                                <el-input v-model="saveDatas.password"></el-input>
                            </el-form-item>
                            <el-form-item label="安装目录" prop="path">
                                <el-input v-model="saveDatas.path" ></el-input>
                            </el-form-item>
                            <el-form-item label="录音文件所在目录" prop="recordPath">
                                <el-input v-model="saveDatas.recordPath" ></el-input>
                            </el-form-item>
                        </div>
                    </fieldset>
                    <fieldset class="layui-elem-field">
                        <legend>IMS服务器配置</legend>
                        <div class="layui-field-box" id="config3">
                            <el-form-item label="IMS服务器域名" prop="crmDomain">
                                <el-input v-model="saveDatas.imsDomain"></el-input>
                            </el-form-item>
                            <el-form-item label="IMS服务器真实地址" prop="realm">
                                <el-input v-model="saveDatas.realm"></el-input>例如：ims.zj.chinamobile.com
                            </el-form-item>
                            <el-form-item label="IMS网关注册代理" prop="register_proxy">
                                <el-input v-model="saveDatas.register_proxy"></el-input>例如：221.131.194.148
                            </el-form-item>
                            <el-form-item label="外拨电话代理" prop="outbound_proxy">
                                <el-input v-model="saveDatas.outbound_proxy"></el-input>例如：221.131.194.148
                            </el-form-item>
                            <el-form-item label="过期时间（S）" prop="expire_seconds">
                                <el-input v-model="saveDatas.expire_seconds"></el-input>例如：3600
                            </el-form-item>
                            <el-form-item label="断线重连时间间隔（S）" prop="ping">
                                <el-input v-model="saveDatas.ping"></el-input>例如：30
                            </el-form-item>
                        </div>
                    </fieldset>
                    <fieldset class="layui-elem-field">
                        <legend>其他配置</legend>
                        <div class="layui-field-box" id="config4">
                            <el-form-item label="是否开启录音" prop="luyin">
                                <el-switch
                                        v-model="saveDatas.luyin"
                                        active-text="开启"
                                        inactive-text="关闭">
                                </el-switch>
                            </el-form-item>
                        </div>
                    </fieldset>
                    <el-form-item label="">
                        <el-button type="primary" @click="save()">保存</el-button>
                    </el-form-item>
                </el-form>
            </form>
        </div>
</template>

<script>
    export default {
        name: "rdhpz",
        beforeCreate: function(){
            this.$nextTick(function () {
                this.$post('cti-manager-config/get-config',{parent_type:"rdhpz"})
                .then((response) => {
                        if (response.data) {
                            var remark = JSON.parse(response.data[0].remark);
                            this.saveDatas = remark;
                            this.saveDatas.luyin = (this.saveDatas.luyin=='true')?true:false;
                        }
                }).catch((response) => {
                    layer.msg("失败！",{icon:2});
                });
            })
        },
        data() {
            return {
                saveDatas:{
                    http:"",
                    domain:"",
                    root:"",
                    path:"",
                    recordPath:"",
                    account:"",
                    password:"",
                    port:"",
                    crmDomain:"",
                    imsDomain:"",
                    realm:"",
                    register_proxy:"",
                    outbound_proxy:"",
                    expire_seconds:"",
                    ping:"",
                    luyin:true,
                }
            }
        },
        methods: {
            save:function () {
                this.$post('cti-manager-config/save-config',{parent_type:"rdhpz",remark:this.saveDatas})
                .then((response) => {//这里使用了ES6的语法
                    if (response.data.res==1) {
                        this.$message({message:'修改成功！',type:'success'})
                    }else{
                        this.$message({message:'修改失败！',type:'error'})
                    }
                }).catch((response) => {
                    this.$message({message:'修改失败！',type:'error'})
                    consoleLog(response)
                });
            }
        }
    }
</script>